<template>
  <div>
    <h1>我的订单</h1>
    <el-table :data="orders" style="width: 100%">
      <el-table-column prop="id" label="订单ID"></el-table-column>
      <el-table-column prop="totalAmount" label="总金额"></el-table-column>
      <el-table-column prop="status" label="状态"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="viewOrder(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getOrders } from '@/api/order';

export default {
  data() {
    return {
      orders: [],
    };
  },
  methods: {
    async fetchOrders() {
      const response = await getOrders(this.$store.state.userId);
      this.orders = response.data;
    },
    viewOrder(orderId) {
      this.$router.push({ path: `/orders/${orderId}` });
    },
  },
  mounted() {
    this.fetchOrders();
  },
};
</script>

<style scoped>
.order-list {
  padding: 20px;
}
</style>